package de.hu.wbi.histoner;

import java.util.Set;

import de.hu.wbi.histoner.HistoNER;
import de.hu.wbi.histoner.HistoneModification;

/**
Copyright 2011,2012 Philippe Thomas
This file is part of histoner.

HistoNer is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
any later version.

HistoNer  is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with HistoNer .  If not, see <http://www.gnu.org/licenses/>.
*/


/**
 * Minimal example for named entity recognition of histone modifications
 * @author philippe
 * @version 1.0
 *
 */
public class Example {


	private static String regexFile;	//Path to file with regular expressions
	private static String text="di-methylation of histone H3 lysine 27";  
	
//	private static String problematic = "53 is phosphorylated at Ser-15 --- 54 are 3";

	/**
	 * Minimal example for running HistoNer on free text
	 * @param args
	 */
	public static void main(String[] args) {
		parseArgs(args);
		HistoNER histoner = new HistoNER(regexFile);
		Set<HistoneModification> modifications= histoner.extractHistoneModifications(text);

		System.err.println(modifications.size() +" histone modifications found");
		for(HistoneModification modification:modifications){
			System.out.println(modification.toBrnoString());
		}
	}
	/**
	 * Used to parse the main method arguments
	 * @param args Arguments from main method
	 */
	private static void parseArgs(String [] args){
		if(args.length != 4 && args.length != 2 ){
			printUsage();
			System.exit(1);
		}
			
		for(int i=0; i<args.length; i+=2){
			if(args[i].equals("-r") || args[i].equals("--regex"))
				regexFile = args[i+1];
			
			else if(args[i].equals("-t") || args[i].equals("--text"))
				text = args[i+1];
			
			else{
				System.err.println("Unknown option " +args[i]);
				printUsage();
				System.exit(1);
			}
		}	
		
		if(regexFile == null){
			System.err.println("Please provide regular expression using the [-r,--regex] parameter");
			System.exit(1);
		}
		
		System.err.println("Using regular expressions from '" +regexFile +"'");
		System.err.println("Text to annotate '" +text +"'\n\n");
	}
	
	private static void printUsage() {
        System.err.println(
        		"Demo application of histoner" +
        		"Usage:\n" +
        		"Regular expression file [-r,--regex]\n" +
        		"Text for annotation (optional) [-t, --text]\n"
        		);		
	}

}
